const Router=require('koa-router')
const router=new Router({prefix:'/address'})
const {auth}=require('../middleWare/auth.middleware')
const {validator}=require('../middleWare/addr.middleware')
const {createAddr,getAddrList,updateAddr,remove}=require('../controller/addr.controller')
router.post('/',auth,validator({
    buyPeople:'string',
    address:'string',
    telephone:{
        type:'string',
        format:/^\d{11}$/
    },
    user_id:'number',
    selected:'bool'

}),createAddr,(ctx)=>{
    const user_id=ctx.state.user.id
    ctx.body={
        message:"添加地址成功"
    }
})
//获取地址列表
router.get('/',auth,getAddrList)
//更新地址
router.put('/:id',auth,validator({
    buyPeople:'string',
    address:'string',
    telephone:{
        type:'string',
        format:/^\d{11}$/
    },
    selected:'bool'
}),updateAddr)
//删除地址
router.patch('/:id',auth,remove)



module.exports=router